<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/4/17/017
 * Time: 8:58
 */

namespace app\Lib\Model\Img;


use app\Lib\Exception\BlException;
use app\Lib\Model\User\User;

class UpdateImg
{
    private $user;
    private $filePath;
    private $fileName;
    public function __construct(User $user,$filePath,$fileName)
    {
        $this->user = $user;
        $this->filePath = $filePath;
        $this->fileName = $fileName;
    }

    /**
     * 上传图片
     * @return int|string
     * @throws BlException
     */
    public function run(){
        $model = new \app\Lib\Model\DbModel\Img();
        $data  = [
            $model->_file_path=>$this->filePath,
            $model->_filename=>$this->fileName,
            $model->_uid=>$this->user->getUid(),
        ];
        $result = $model->insert($data,false,true);
        if(!$result){
            throw new BlException('上传失败');
        }

        return $result;
    }

}